home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / QuickDraw™ GX v1.0ß2 / Sample Code / Graphics Samples / Caps Attached To a Curve ƒ / caps attached to a curve.c next >
Encoding:
C/C++ Source or Header  |  1993-09-14  |  4.4 KB  |  158 lines  |  [TEXT/KAHL]

  1. /*
  2.     caps attached to a curve.c
  3.     
  4.     This file contains the calls to create a "thick" curve and attach a cap to each end of the curve. 
  5.         
  6.     NOTES: 
  7.     • This file requires the following files to run correctly:
  8.         "graphics shell.c", "color library.c", "graphics debug library.c", "shape library.c", 
  9.         "transform library.c".
  10.         
  11.     • This file prints the "best" in landscape mode.
  12.  
  13.     ©1992 - 1993 Apple Computer, Inc. 
  14.     All rights reserved. 
  15. */
  16.  
  17.  
  18. #include <events.h>
  19. #include <windows.h>
  20.  
  21. #include "graphics debugging.h"
  22. #include "graphics libraries.h"
  23. #include "graphics toolbox.h"
  24. #include "graphics shell.h"
  25.  
  26. //
  27. //  Set up the title and size of the window 
  28. //
  29. Str255         gWindowTitle = "\p Caps Attached To a Curve";
  30. Rect         gWindowQDRect  = {50, 20, 275, 350};
  31.  
  32. //
  33. //    If gDebugging = TRUE, graphics library errors and notices will be posted.  This functionality  will only work with 
  34. //    the "debugging" version of the QuickDraw GX init.  If this version of the init is not installed, nothing bad will happen, 
  35. //    but these  functions will not work. 
  36. //
  37. Boolean        gDebugging = true;
  38.  
  39. //
  40. //    Set  "gGiveMeValidation" to TRUE, if you will receive run-time validation.  
  41. //
  42. Boolean        gGiveMeValidation = true;
  43.  
  44. //
  45. //    gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
  46. //    in main () within graphics shell.c.  You can determine the amount of graphics gxHeap required by using GraphicsBug.
  47. //    With  gGraphicsHeapSize set to 10k, I had 3 free blocks left in the graphics gxHeap. Sounds good to me.
  48. //
  49. long        gGraphicsHeapSize = 10;
  50.  
  51. gxShape     gShape;
  52. short        gClickNumber;
  53.  
  54.  
  55.  
  56. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  57.  
  58. void DoInitialization(gWindow)
  59. WindowPtr gWindow;
  60. {
  61.     gxCurve         curveGeometry = {ff(25), ff(125), ff(100), 0, ff(225), ff(125)};    
  62.     gxShape         arrowHead, arrowTail;
  63.     long            arrowHeadPolygonGeometry[] = {    4, // Number of points,
  64.                                                        -ff(2)-fixed1/2, 0,
  65.                                                         0, fixed1, 
  66.                                                          fixed1 + fixed1/2, 0, 
  67.                                                        0, -fixed1};
  68.                                                
  69.     long             arrowTailPolygonGeometry[] = {    5, // Number of points,
  70.                                                      -fixed1, 0, 
  71.                                                       0, fixed1, 
  72.                                                       ff(2), fixed1, 
  73.                                                       ff(2), -fixed1, 
  74.                                                       0, -fixed1};
  75.      gxCapRecord     theCapRecord;
  76.  
  77.      InitCommonColors();
  78.  
  79.     gShape = GXNewCurve (&curveGeometry);
  80.     
  81.     //
  82.     //    Create the cap shapes
  83.     //
  84.     arrowHead = NewPolygon((gxPolygon *) &arrowHeadPolygonGeometry);
  85.     arrowTail = NewPolygon((gxPolygon *) &arrowTailPolygonGeometry);
  86.  
  87.     //
  88.     //    Add the appropriate shape for start cap and end cap
  89.     //
  90.     theCapRecord.startCap = arrowHead;
  91.     theCapRecord.endCap = arrowTail;
  92.     theCapRecord.attributes = gxNoAttributes;
  93.  
  94.     //
  95.     //    Add the cap record to our "gShape"
  96.     //
  97.     GXSetShapeCap(gShape, &theCapRecord);
  98.     
  99.     //
  100.     //    We do no need the cap shapes because they have been copied into the cap record which is
  101.     //    now part of the style used by "gShape".
  102.     //
  103.     GXDisposeShape(arrowHead);
  104.     GXDisposeShape(arrowTail);
  105.     
  106.     GXSetShapePen(gShape, ff(15));
  107.     SetShapeCommonColor(gShape, red);
  108.     GXMoveShape (gShape, ff(35), 0);
  109.     
  110.     gClickNumber = 1;
  111. }
  112.  
  113. /*------ DoClick ---------------------------------------------------------------------------------------*/
  114.  
  115. void DoClick(gWindow)
  116. WindowPtr gWindow;
  117. {
  118. }
  119.  
  120.  
  121.  
  122.  
  123. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  124.  
  125. void DoDraw(gWindow)
  126. WindowPtr gWindow;
  127. {
  128.     GXDrawShape (gShape);
  129. }
  130.  
  131.  
  132. /*------ DoDispose -------------------------------------------------------------------------------------*/
  133.  
  134. void DoDispose(gWindow)
  135. WindowPtr gWindow;
  136. {
  137.     /**  
  138.         You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  139.         form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  140.         call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  141.         SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  142.         can turn notices on in this file by setting gDebugging = TRUE (above).
  143.     **/
  144.     GXDisposeShape(gShape);  
  145.      GXDisposeShape(gWindowBoundsShape);  
  146.        DisposeCommonColors();
  147.        DisposeWindow(gWindow);
  148. }
  149.     
  150.  
  151.  
  152. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  153.  
  154. void DoIdle(gWindow)
  155. WindowPtr gWindow;
  156. {
  157. }
  158.